package com.hisan.freeride.home.adapter;

import com.github.library.BaseQuickAdapter;
import com.github.library.BaseViewHolder;
import com.hisan.freeride.R;
import com.hisan.freeride.home.model.Insurance;
import com.library.CustomTextView;

import java.util.List;

/**
 * 首页行程列表适配器
 * Created by yu on 2017/1/17.
 */

public class InsuranceAdapter extends BaseQuickAdapter<Insurance,BaseViewHolder>{
    private ButtonClickListener mButtonClickListener;
    private onItemClickListener mOnItemClickListener;
    public InsuranceAdapter(List<Insurance> data) {
        super(R.layout.insurance_list,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Insurance item) {
        helper.setText(R.id.cart_no,"订单编号:"+item.getOrder_no());
        helper.setText(R.id.title,item.getSafety().getTitle());
        helper.setText(R.id.content,item.getSafety().getContent());
        helper.setText(R.id.time,item.getCreate_time());
        helper.getView(R.id.home).setOnClickListener(v -> {
            if (mOnItemClickListener!=null){
                mOnItemClickListener.onItemClick(item);
            }
        });
        CustomTextView status=  helper.getView(R.id.status);
        switch (item.getOrder_status()){
            case 0:
                status.setText("去支付");
                status.setOnClickListener(v -> {
                if (mButtonClickListener!=null){
                    mButtonClickListener.onClick(item);
                }
                });
                break;
            case 1:
                status.setText("已支付");
                status.setOnClickListener(null);
                break;
            case 2:
                status.setText("已生效");
                status.setOnClickListener(null);
                break;
            case -1:
                status.setText("已取消");
                status.setOnClickListener(null);
                break;
        }
    }
    /**
     * 自定义的recyclerView点击监听
     */
    public interface onItemClickListener {
        void onItemClick(Insurance data);
    }
    /**
     * 按钮的点击监听
     */
    public interface ButtonClickListener {
        void onClick(Insurance data);
    }
    public void setButtonClickListener(ButtonClickListener listener) {
        mButtonClickListener = listener;
    }
    public void setOnItemClickListener(onItemClickListener listener) {
        mOnItemClickListener = listener;
    }
}
